﻿<div [@routerTransition]>
    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("ArticleInfo")}}</span>
                </h3>
            </div>
            <div class="col-sm-6 text-right">
                <audit-log serviceName="ArticleInfoAppService" objectName="Magicodes.Admin.Core.Custom.Contents.ArticleInfo"></audit-log>
                <button type="button" class="btn btn-success" (click)="exportToExcel()">
                    <i class="fa fa-file-excel-o"></i> {{l("ExportToExcel")}}
                </button>
                <button class="btn btn-primary blue" (click)="createArticleInfo()">
                    <i class="fa fa-plus"></i>{{l("Create")}}
                </button>
                <button type="button" class="btn btn-metal" (click)="getArticleInfos()">
                    <i class="fa fa-refresh"></i> {{l("Refresh")}}
                </button>
                <button type="button" class="btn default" (click)="getRecycleData()">
                    <i class="fa fa-recycle"></i> {{filters.isOnlyGetRecycleData?l('Close'):l('RecycleBin')}}
                </button>
            </div>
        </div>
    </div>
    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="m-form m-form--label-align-right">
                    <form (submit)="getArticleInfos()" autocomplete="off">
                        <div class="form-body row">
                            <div class="col-xl-6">
                                <label>{{l("Filter")}}</label>
                                <div class="input-group">
                                    <input [(ngModel)]="filters.filterText" name="Filter" class="form-control"
                                        placeholder="{{l('SearchWithThreeDot')}}" type="text">
                                </div>
                            </div>
                            <div class="col-xl-6">
                                <label>{{l("ColumnInfo")}}</label>
                                <data-combo [(selectedValue)]="filters.columnInfoId" [values]="columnInfoComboItemDtoList"></data-combo>
                            </div>
                        </div>
                        <div *ngIf="advancedFiltersAreShown" class="row">
                            <div class="col-xl-6">
                                <div class="m-checkbox-list">
                                    <label class="m-checkbox">
                                        <input type="checkbox" [(ngModel)]="filters.creationDateRangeActive" id="articleTable_CreationDateRangeActive"
                                            name="CreationDateRangeActive" value="true">
                                        {{l('CreationTime')}}
                                        <span></span>
                                    </label>
                                </div>
                                <input class="form-control" name="CreationDateRange" [attr.disabled]="!filters.creationDateRangeActive ? 'disabled' : null"
                                    #drpCreationDateRange="bsDaterangepicker" bsDaterangepicker dateRangePickerInitialValue readonly="readonly"
                                    [(ngModel)]="creationDateRange">
                            </div>

                            <div class="col-xl-6">
                                <div class="m-checkbox-list">
                                    <label class="m-checkbox">
                                        <input type="checkbox" [(ngModel)]="filters.updateDateRangeActive" id="articleTable_UpdateDateRangeActive"
                                            name="UpdateDateRangeActive" value="true">
                                        {{l('UpdateDateRange')}}
                                        <span></span>
                                    </label>
                                </div>
                                <input class="form-control" name="UpdateDateRange" [attr.disabled]="!filters.updateDateRangeActive ? 'disabled' : null"
                                    #drpCreationDateRange="bsDaterangepicker" bsDaterangepicker dateRangePickerInitialValue readonly="readonly"
                                    [(ngModel)]="updateDateRange">
                            </div>
                            <div class="col-md-6">
                                <label for="SubmenuToggle">{{l("IsActive")}}</label>
                                <select id="IsActive" name="IsActive" class="form-control" [(ngModel)]="filters.isActive">
                                    <option value="all">{{l("All")}}</option>
                                    <option value="yes">{{l("Yes")}}</option>
                                    <option value="no">{{l("No")}}</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label for="SubmenuToggle">{{l("IsNeedAuthorizeAccess")}}</label>
                                <select id="IsNeedAuthorizeAccess" name="IsNeedAuthorizeAccess" class="form-control"
                                    [(ngModel)]="filters.isNeedAuthorizeAccess">
                                    <option value="all">{{l("All")}}</option>
                                    <option value="yes">{{l("Yes")}}</option>
                                    <option value="no">{{l("No")}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="row m--margin-bottom-10">
                            <div class="col-sm-6">
                                <span class="clickable-item text-muted" *ngIf="!advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown">
                                    <i class="fa fa-angle-down"></i> {{l("ShowAdvancedFilters")}}
                                </span>
                                <span class="clickable-item text-muted" *ngIf="advancedFiltersAreShown" (click)="advancedFiltersAreShown=!advancedFiltersAreShown">
                                    <i class="fa fa-angle-up"></i> {{l("HideAdvancedFilters")}}
                                </span>
                            </div>
                        </div>
                    </form>
                </div>

                <div class="row align-items-center">
                    <!--<Primeng-Datatable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable (onLazyLoad)="getArticleInfos($event)" [value]="primengTableHelper.records"
                            rows="{{primengTableHelper.defaultRecordsCountPerPage}}" [paginator]="false" [lazy]="true"
                            [responsive]="primengTableHelper.isResponsive" [scrollable]="true" [style]="{width:'100%'}">
                            <ng-template pTemplate="header">
                                <tr>

                                    <th style="width:130px">{{l('Actions')}}</th>
                                    <th pSortableColumn="title" style="width:200px">{{l('Title')}}
                                        <p-sortIcon field="title"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="code" style="width:200px">{{l('Code')}}
                                        <p-sortIcon field="code"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="publisher" style="width:200px">{{l('Publisher')}}
                                        <p-sortIcon field="publisher"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="columnInfo" style="width:200px">{{l('ColumnInfo')}}
                                        <p-sortIcon field="columnInfo"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="articleSourceInfo" style="width:200px">{{l('ArticleSourceInfo')}}
                                        <p-sortIcon field="articleSourceInfo"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="releaseTime" style="width:200px">{{l('ReleaseTime')}}
                                        <p-sortIcon field="releaseTime"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="isActive" style="width:200px">{{l('IsActive')}}
                                        <p-sortIcon field="isActive"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="isNeedAuthorizeAccess" style="width:200px">{{l('IsNeedAuthorizeAccess')}}
                                        <p-sortIcon field="isNeedAuthorizeAccess"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="seoTitle" style="width:200px">{{l('SeoTitle')}}
                                        <p-sortIcon field="seoTitle"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="staticPageUrl" style="width:200px">{{l('StaticPageUrl')}}
                                        <p-sortIcon field="staticPageUrl"></p-sortIcon>
                                    </th>
                                    <th style="width:200px">{{l('Cover')}}</th>
                                    <th style="width:600px">{{l('PictureManage')}}</th>
                                    <th pSortableColumn="articleTagInfos" style="width:200px">{{l('ArticleTagInfos')}}
                                        <p-sortIcon field="articleTagInfos"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="url" style="width:200px">{{l('Url')}}
                                        <p-sortIcon field="url"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="recommendedType" style="width:200px">{{l('RecommendedType')}}
                                        <p-sortIcon field="recommendedType"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="viewCount" style="width:200px">{{l('ViewCount')}}
                                        <p-sortIcon field="viewCount"></p-sortIcon>
                                    </th>
                                    <th pSortableColumn="creationTime" style="width:200px">{{l('CreationTime')}}
                                        <p-sortIcon field="creationTime"></p-sortIcon>
                                    </th>
                                </tr>
                            </ng-template>

                            <ng-template pTemplate="body" let-record="$implicit">
                                <tr>
                                    <td style="width: 130px" [hidden]="!isGrantedAny('Pages.ArticleInfo.Edit', 'Pages.ArticleInfo.Delete', 'Pages.ArticleInfo.Restore')">
                                        <div class="btn-group dropdown" dropdown container="body">
                                            <button dropdownToggle class="dropdown-toggle btn btn-sm btn-primary">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
                                            </button>
                                            <ul class="dropdown-menu" *dropdownMenu>
                                                <li *ngIf="!record.isDeleted && !record.isStatic">
                                                    <a href="javascript:;" *ngIf="permission.isGranted('Pages.ArticleInfo.Edit')" (click)="editArticleInfo(record.id)">{{l('Edit')}}</a>
                                                </li>
                                                <li *ngIf="!record.isDeleted && !record.isStatic">
                                                    <a href="javascript:;" *ngIf="permission.isGranted('Pages.ArticleInfo.Delete')" (click)="deleteArticleInfo(record.id)">{{l('Delete')}}</a>
                                                </li>
                                                <li *ngIf="!record.isDeleted">
                                                    <a href="javascript:;" *ngIf="permission.isGranted('Pages.ArticleInfo.Edit')" (click)="articleTagInfoModal.show(record.id)">{{l('ArticleTagInfo')}}</a>
                                                </li>
                                                <li *ngIf="!record.isDeleted">
                                                    <a href="javascript:;" *ngIf="permission.isGranted('Pages.ArticleInfo.Edit')" (click)="fileUploadModal.show(record.id)">{{l('PictureManage')}}</a>
                                                </li>
                                                <li *ngIf="record.isDeleted">
                                                    <a href="javascript:;" *ngIf="permission.isGranted('Pages.ArticleInfo.Restore')" (click)="restore(record.id)">{{l('Restore')}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="width:200px">
                                        {{record.title}}
                                        <span *ngIf="record.isStatic" class="m-badge m-badge--brand m-badge--wide"
                                            data-toggle="tooltip" title="{{l('StaticArticleInfo_Tooltip')}}"
                                            data-placement="top">
                                            {{l('Static')}}
                                        </span>
                                    </td>
                                    <td style="width:200px">{{record.code}}</td>
                                    <td style="width:200px">{{record.publisher}}</td>
                                    <td style="width:200px">{{record.columnInfo}}</td>
                                    <td style="width:200px">{{record.articleSourceInfo}}</td>
                                    <td style="width:200px">
                                        {{ record.releaseTime ? (record.releaseTime | momentFormat:'L LT') : '-'}}
                                    </td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsActiveSwitch($event,record.id)" [(ngModel)]="record.isActive"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">
                                        <p-inputSwitch (onChange)="handleIsNeedAuthorizeAccessSwitch($event,record.id)"
                                            [(ngModel)]="record.isNeedAuthorizeAccess"></p-inputSwitch>
                                    </td>
                                    <td style="width:200px">{{record.seoTitle}}</td>
                                    <td style="width:200px">{{record.staticPageUrl}}</td>
                                    <td style="width:200px">
                                            <object-imageList objectTypeName="ArticleInfo" [(objectId)]="record.id"
                                            isCover="true"></object-imageList>
                                    </td>
                                    <td style="width:600px">
                                        <object-imageList objectTypeName="ArticleInfo" [(objectId)]="record.id" isCover="false"></object-imageList>
                                    </td>
                                    <td style="width:200px">{{record.articleTagInfos}}</td>
                                    <td style="width:200px">{{record.url}}</td>
                                    <td style="width:200px">{{getRecommendedTypeText(record.recommendedType)}}</td>
                                    <td style="width:200px">{{record.viewCount}}</td>
                                    <td style="width:200px">
                                        {{ record.creationTime ? (record.creationTime | momentFormat:'L LT') : '-'}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>

                        <div class="primeng-paging-container">
                            <p-paginator rows="{{primengTableHelper.defaultRecordsCountPerPage}}" #paginator
                                (onPageChange)="getArticleInfos($event)" [totalRecords]="primengTableHelper.totalRecordsCount"
                                [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                            </p-paginator>
                            <span class="total-records-count">
                                {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                            </span>
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->
                </div>
            </div>
        </div>
    </div>

    <createOrEditArticleInfoModal #createOrEditArticleInfoModal (modalSave)="getArticleInfos()"></createOrEditArticleInfoModal>

    <ArticleTagInfoModal #ArticleTagInfoModal (close)="getArticleInfos()"></ArticleTagInfoModal>

    <fileUploadModal #fileUploadModal objectTypeName="ArticleInfo"></fileUploadModal>
</div>